package com.dycx.user.converter;

import cn.hutool.core.bean.BeanUtil;
import com.dycx.user.enums.WithdrawDepositStatusEnum;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.user.entity.WithdrawDepositDO;
import com.dycx.user.vo.WithdrawDepositVO;
import com.dycx.user.dto.WithdrawDepositDTO;

/**
 * 资金明细(WithdrawDepositApply)实体转换类
 *
 * @author wuzongbing
 * @since 2024-08-22 01:03:00
 */


@Data
public class WithdrawDepositConverter implements Serializable {
    public static WithdrawDepositDO dtoToEntity(WithdrawDepositDTO dto) {
        if (dto == null) return null;
        WithdrawDepositDO entity = BeanUtil.toBean(dto, WithdrawDepositDO.class);
        return entity;
    }

    public static WithdrawDepositVO entityToVo(WithdrawDepositDO entity) {
        if (entity == null) return null;
        WithdrawDepositVO vo = BeanUtil.toBean(entity, WithdrawDepositVO.class);
        vo.setResultName(WithdrawDepositStatusEnum.converter(vo.getResult()));
        return vo;
    }

    public static List<WithdrawDepositVO> entityToVoList(List<WithdrawDepositDO> entityList) {
        List<WithdrawDepositVO> voList = new ArrayList<>();
        for (WithdrawDepositDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<WithdrawDepositVO> entityToVoPage(Page<WithdrawDepositDO> page) {

        List<WithdrawDepositVO> newRecords = new ArrayList<>();

        List<WithdrawDepositDO> records = page.getRecords();
        for (WithdrawDepositDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<WithdrawDepositVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
